Trò chơi Angry Birds trong UNITY Engine
31.659 lượt xem;
- Vector3XTweenProperty.cs
- genericTypes /
- properties /
- GoKit /
- Plugins /
- Assets /
- project /
1 using UnityEngine;
2 using System;
3 using System.Collections;
4
5
6 public class Vector3XTweenProperty : AbstractVector3TweenProperty, IGenericProperty
7 {
8 public string propertyName { get; private set; }
9 protected Action<Vector3> _setter;
10 protected Func<Vector3> _getter;
11
12 protected new float _originalEndValue;
13 protected new float _startValue;
14 protected new float _endValue;
15 protected new float _diffValue;
16
17
18 public Vector3XTweenProperty( string propertyName, float endValue, bool isRelative = false )
19 {
20 this.propertyName = propertyName;
21 _isRelative = isRelative;
22 _originalEndValue = endValue;
23 }
24
25
26 /// <summary>
27 /// validation checks to make sure the target has a valid property with an accessible setter
28 /// </summary>
29 public override bool validateTarget( object target )
30 {
31 // cache the setter
32 _setter = GoTweenUtils.setterForProperty<Action<Vector3>>( target, propertyName );
33 return _setter != null;
34 }
35
36
37 public override void prepareForUse()
38 {
39 // retrieve the getter
40 _getter = GoTweenUtils.getterForProperty<Func<Vector3>>( _ownerTween.target, propertyName );
41
42 _endValue = _originalEndValue;
43
44 // if this is a from tween we need to swap the start and end values
45 if( _ownerTween.isFrom )
46 {
47 _startValue = _endValue;
48 _endValue = _getter().x;
49 }
50 else
51 {
52 _startValue = _getter().x;
53 }
54
55 // prep the diff value
56 if( _isRelative && !_ownerTween.isFrom )
57 _diffValue = _endValue;
58 else
59 _diffValue = _endValue - _startValue;
60 }
61
62
63 public override void tick( float totalElapsedTime )
64 {
65 var currentValue = _getter();
66 currentValue.x = _easeFunction( totalElapsedTime, _startValue, _diffValue, _ownerTween.duration );
67
68 _setter( currentValue );
69 }
70
71 }
2 using System;
3 using System.Collections;
4
5
6 public class Vector3XTweenProperty : AbstractVector3TweenProperty, IGenericProperty
7 {
8 public string propertyName { get; private set; }
9 protected Action<Vector3> _setter;
10 protected Func<Vector3> _getter;
11
12 protected new float _originalEndValue;
13 protected new float _startValue;
14 protected new float _endValue;
15 protected new float _diffValue;
16
17
18 public Vector3XTweenProperty( string propertyName, float endValue, bool isRelative = false )
19 {
20 this.propertyName = propertyName;
21 _isRelative = isRelative;
22 _originalEndValue = endValue;
23 }
24
25
26 /// <summary>
27 /// validation checks to make sure the target has a valid property with an accessible setter
28 /// </summary>
29 public override bool validateTarget( object target )
30 {
31 // cache the setter
32 _setter = GoTweenUtils.setterForProperty<Action<Vector3>>( target, propertyName );
33 return _setter != null;
34 }
35
36
37 public override void prepareForUse()
38 {
39 // retrieve the getter
40 _getter = GoTweenUtils.getterForProperty<Func<Vector3>>( _ownerTween.target, propertyName );
41
42 _endValue = _originalEndValue;
43
44 // if this is a from tween we need to swap the start and end values
45 if( _ownerTween.isFrom )
46 {
47 _startValue = _endValue;
48 _endValue = _getter().x;
49 }
50 else
51 {
52 _startValue = _getter().x;
53 }
54
55 // prep the diff value
56 if( _isRelative && !_ownerTween.isFrom )
57 _diffValue = _endValue;
58 else
59 _diffValue = _endValue - _startValue;
60 }
61
62
63 public override void tick( float totalElapsedTime )
64 {
65 var currentValue = _getter();
66 currentValue.x = _easeFunction( totalElapsedTime, _startValue, _diffValue, _ownerTween.duration );
67
68 _setter( currentValue );
69 }
70
71 }